package com.second.app.thread.fair_nofair_test;

import java.util.concurrent.locks.ReentrantLock;

/**
 * @author gyz
 * @date 2021/2/2 13:51
 */
public class Service {

    private ReentrantLock lock;

    public Service(boolean isFair) {
        lock = new ReentrantLock(isFair);
    }

    public void serviceMethod() {
        lock.lock();
        try {
            System.out.println("ThreadName=" + Thread.currentThread().getName() + "获得了锁");
        } finally {
            lock.unlock();
        }

    }
}
